import {mainNetWork,testNetWork} from "./env"
import { ethers } from "ethers";
export async function  provider() {
    const main = async () => {
      // 1. 通过RPC创建 Provider 类
      const providerETH = new ethers.providers.JsonRpcProvider(mainNetWork)
      const providerTest = new ethers.providers.JsonRpcProvider(testNetWork)
      // console.log('provider',providerETH)
      // 2.0 利用 provider 实例读取链上的数据
      // const balance = await providerETH.getBalance('vitalik.eth')
      // console.log('V神钱包余额', ethers.utils.formatEther(balance))//'wei'
      // 2.1 读取 provider 网络信息
      // const netWorkName = await providerETH.getNetwork()
      // console.log('当前网络信息',netWorkName)
      // const testNetWorkName = await providerTest.getNetwork()
      // console.log('测试网的信息',testNetWorkName)
      // 2.3 读取当前的区块高度
      // const blockNumber = await providerETH.getBlockNumber()
      // console.log('区块高度',blockNumber)
      // 2.4 查询 gas 价格
      // const gasPrice = await providerETH.getGasPrice()
      // console.log('当前gas价格',ethers.utils.formatEther(gasPrice.toNumber()))
      // 2.5 查询区块信息
      // const blockInfo = await providerETH.getBlock(blockNumber)
      // console.log('区块信息',blockInfo)
      // 2.6 查询区块合约
      // const contract = await providerETH.getCode('registrar.firefly.eth')
      // console.log('合约源码',contract)
    }
  main() 
}